<template>
    <div>
        <h1 style="color: red;">用药信息-修改</h1>
        <table class="table">
            <thead>
                <tr>
                    <td><span style="color: red;">*</span> 药品名称</td>
                    <td>
                       <input v-model="obj.name" type="text">
                    </td>
                </tr>
                <tr>
                    <td>科室</td>
                    <td>
                        <select  v-model="obj.oid" @click="officelist">
                            <option  value="0">请选择</option>
                            <option v-for="item in list"  :value="item.id">{{item.officeName}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>用药日期</td>
                    <td>
                        <input v-model="obj.createTime" type="date">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span> 病人名称</td>
                    <td>
                        <input v-model="obj.peoName" type="text">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span> 病房号码</td>
                    <td>
                        <input v-model="obj.warName" type="text">
                    </td>
                </tr>
                <tr>
                    <td>用药状态</td>
                    <td>
                       <input v-model="obj.isAction" type="radio" name="isAction" :value="true">已完成
                       <input v-model="obj.isAction" type="radio" name="isAction" :value="false">未完成
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span> 配药医生</td>
                    <td>
                        <input v-model="obj.doctName" type="text">
                    </td>
                </tr>
                <tr>
                    <td>是否删除</td>
                    <td>
                        <input v-model="obj.isDelete" type="radio" name="isDelete" :value="true">已删除
                        <input v-model="obj.isDelete" type="radio" name="isDelete" :value="false">未删除
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="button" value="修改" @click="updatedoctor" class="btn">
                    </td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
const route=useRoute();
const router=useRouter();

onMounted(()=>{
    GetData();
})
const GetData=()=>{
    let id=route.query.id;
    axios.get("https://localhost:7187/api/Doctor/GetDoctorId",{params:{id:id}}).then(res=>{
        obj.value=res.data;
    })
}

const list=ref([{
    "id": 1,
    "img": "/pic/1.jpg",
    "createTime": "2025-02-18T05:47:12.254",
    "officeName": "内科"
}])
const officelist=()=>{
    axios.get("https://localhost:7187/api/Office/GetOfficeList").then(res=>{
       list.value=res.data;
    })
}

const obj=ref({
    "id": 0,
    "name": "",
    "oid": 0,
    "createTime": "2025-02-18T07:43:00.507Z",
    "peoName": "",
    "warName": "",
    "isAction": false,
    "doctName": "",
    "isDelete": false
})
const updatedoctor=()=>{
    if(obj.value.name==""){
        alert('药品名称不得为空')
        return;
    }
    if(obj.value.peoName==""){
        alert('病人名称不得为空')
        return;
    }
    if(obj.value.warName==""){
        alert('病房号码不得为空')
        return;
    }
    if(obj.value.doctName==""){
        alert('配药医生不得为空')
        return;
    }

    axios.put("https://localhost:7187/api/Doctor/UpdateDoctor",obj.value).then(res=>{
        if(res.data>0){
            alert('修改成功')
            router.push("/ShowDoctor");
        }
        else{
            alert('修改失败')
        }
    })
}
</script>

<style scoped>

</style>